package com.youku.expression.ast;

/**
 * 自增
 * 
 * @author loda
 *
 */
public class IncrAst extends UnaryAst {

	public IncrAst(boolean prefix, Ast ast) {
		super(prefix, ast);
		operation="++";
	}

	@Override
	public String toString() {
		StringBuilder builder=new StringBuilder();
		if(prefix){
			builder.append(operation).append('(').append(element()).append(')');
		}else{
			builder.append('(').append(element()).append(')').append(operation);
		}
		return builder.toString();
	}

	@Override
	public Object operate(Object element) {
		if (element instanceof Number) {
			if (element instanceof Double) {
				return ((Number) element).doubleValue() + 1;
			} else if (element instanceof Float) {
				return ((Number) element).floatValue() + 1;
			} else if (element instanceof Long) {
				return ((Number) element).longValue() + 1;
			} else {
				return ((Number) element).intValue() + 1;
			}
		}

		throw new RuntimeException("这里应该是个数字");
	}

}
